<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <a-col :md="6" :sm="8">
            <a-form-item label="举办地址">
              <a-input placeholder="请输入举办地址" v-model="queryParam.address"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="展会主题">
              <a-input placeholder="请输入展会主题" v-model="queryParam.theme"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="展位数">
              <a-input placeholder="请输入展位数" v-model="queryParam.boothNum"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8" >
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus" v-if="userAuth2btn=='4'">新增</a-button>
      <!-- <a-button type="primary" icon="download" @click="handleExportXls('展会信息')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload> -->
      <a-dropdown v-if="selectedRowKeys.length > 0 && (userAuth2btn ==3 || userAuth2btn ==4)">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
      style="wordBreak: break-all"
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :scroll="{ x: '100%' }"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无此图片</span>
          <div v-else @click="jumpProview(text)">
            <img                     
              :src="getImgView(text)"
              height="25px"
              alt="图片不存在"
              style="max-width:80px;font-size: 12px;font-style: italic;"            
            />
          </div>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)" v-if="record.meetingStatus != 2">编辑</a>
          <a-divider type="vertical" v-if="record.meetingStatus != 2"/>
          <a @click="addHourse(record)" v-if="record.meetingStatus != 2">新增展位</a>
          <a-divider type="vertical" v-if="record.meetingStatus == 0"/>
          <a-dropdown v-if="record.meetingStatus ==0" >
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
      <a-modal
        title="新增展位"
        :visible="visibleShow"
        :confirm-loading="confirmLoading"
        @ok="handleOk"
        @cancel="handleCancel"
      >
      <div v-if="addList.locationType==0">
        <span>房间号：</span>
        <!-- <a-input style="display: inline-block;width:60%;" v-model="hourseVal" placeholder="请输入房间号例如101/102"></a-input> -->
        <template v-for="(tag, index) in tags">
          <a-tooltip v-if="tag.length > 20" :key="tag" :title="tag">
            <a-tag :key="tag" :closable="index !== 0" :afterClose="() => handleClose(tag)">
              {{`${tag.slice(0, 20)}...`}}
            </a-tag>
          </a-tooltip>
          <a-tag v-else :key="tag" closable :afterClose="() => handleClose(tag)">
            {{tag}}
          </a-tag>
        </template>
        <a-input
          v-if="inputVisible && showTagLen"
          ref="input"
          type="text"
          size="small"
          :style="{ width: '78px' }"
          v-model="inputValue"
          @change="handleInputChange"
          @blur="handleInputConfirm"
          @keyup.enter="handleInputConfirm"
        />
        <a-tag v-if="!inputVisible && showTagLen" @click="showInput" style="background: #fff; borderStyle: dashed;">
          <a-icon type="plus" /> New Tag
        </a-tag>
      </div>
      <div v-if="addList.locationType==1">
        <div>
          <span>新增展位行：</span>
          <a-input-number :min="0" :max="50" style="display: inline-block;width:60%;" v-model="lineVal" placeholder="请输入展位行"/>
        </div>
        <div style="margin-top:20px;">
          <span>新增展位列：</span>
          <a-input-number :min="0" :max="50" style="display: inline-block;width:60%;" v-model="clomnVal" placeholder="请输入展位列"/>
        </div>
      </div>
      </a-modal>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <JProviewImg v-if="showImg" @closeProview="closeProview" :imgurl="proviewUrl"></JProviewImg>
    <exhibition_meeting_info-modal ref="modalForm" @ok="modalFormOk"></exhibition_meeting_info-modal>
  </a-card>
</template>

<script>
  import Exhibition_meeting_infoModal from './modules/Exhibition_meeting_infoModal'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import JProviewImg from '@/components/jeecg/JProviewImg.vue'
  import { postAction,getAction } from '@/api/manage'
  import { initDictOptions, filterMultiDictText } from '@/components/dict/JDictSelectUtil'

  export default {
    name: "Exhibition_meeting_infoList",
    mixins:[JeecgListMixin],
    components: {
      Exhibition_meeting_infoModal,
      JProviewImg
    },
    data () {
      return {
        inputValue: '',
        tags: [],
        inputVisible: false,
        showTagLen: true,
        addList:{},
        lineVal:0,
        clomnVal:0,
        hourseVal:"",
        visibleShow:false,
        confirmLoading:false,
        description: '展会信息管理页面',
        proviewUrl:"",
        showImg:false,
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
           },
		   {
            title: '展会主题',
            align:"center",
            dataIndex: 'theme',
            width:120
           },
		   {
            title: '举办地址',
            align:"center",
            dataIndex: 'address',
            width:150
           },
		   {
            title: '展位数',
            align:"center",
            dataIndex: 'boothNum',
            width:70
           },
           {
            title: '主票数',
            align:"center",
            dataIndex: 'mainTicketNumber',
            width:70
           }, 
           {
            title: '次票数',
            align:"center",
            dataIndex: 'attchedTicketNumber',
            width:70
           }, 
           {
            title: '剩余门票',
            align:"center",
            dataIndex: 'ticketsNum',
            width:70
           },
          {
            title:'场地类型',
            align:"center",
            children: [
              {
                title: '酒店',
                align:"center",
                children: [
                   {
                    title: '酒店房间号',
                    align:"center",
                    dataIndex: 'hotelNumber',
                    width: 260
                   },
                ],
              },
              {
                title: '大厅',
                align:"center",
                children: [
                   {
                    title: '场地编排列',
                    align:"center",
                    dataIndex: 'columnNumber',
                    width:70
                   },
                   {
                    title: '场地编排行',
                    align:"center",
                    dataIndex: 'lineNumber',
                    width:70
                   },
                ],
              },
            ],
          },
		   {
            title: '开始时间',
            align:"center",
            dataIndex: 'startTime',
            width:120
           },
		   {
            title: '结束时间',
            align:"center",
            dataIndex: 'endTime',
            width:120
           },
		  //  {
      //       title: '是否售完',
      //       align:"center",
      //       dataIndex: 'ticketsNum',
      //       customRender: text => {
      //         return text == 0?"是":"否"
      //       }
      //      },
		  //  {
      //       title: '海报',
      //       align:"center",
      //       dataIndex: 'poster1',
      //       scopedSlots: { customRender: 'imgSlot' },
      //       width:60
      //      },
      //      {
      //       title: '场地使用许可',
      //       align:"center",
      //       dataIndex: 'licenseFile',
      //       scopedSlots: { customRender: 'imgSlot' },
      //       width:60
      //      },
		  //  {
      //       title: '备注',
      //       align:"center",
      //       dataIndex: 'remark',
      //       width: 150
      //      },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            width:150,
            scopedSlots: { customRender: 'action' },
          }
        ],
      userAuth2btn:"1",
      dictOptions: {
        ticketsStatus: []
      },
      url: {
            list: "/exhibition/exhibition_meeting_info/list",
            delete: "/exhibition/exhibition_meeting_info/delete",
            deleteBatch: "/exhibition/exhibition_meeting_info/deleteBatch",
            exportXlsUrl: "exhibition/exhibition_meeting_info/exportXls",
            importExcelUrl: "exhibition/exhibition_meeting_info/importExcel",
        },
    }
  },
  watch:{
    tags(val){
      if(typeof val == 'object'){
        this.showTagLen = true;
      }else{
        this.tags.push(val);
      }
    }
  },
  mounted(){
    getAction("/block/blockManufacturerInfo/userAuth2btn")
        .then(res => {
          if (res.success) {
            this.userAuth2btn = res.result.status;
          } else {
            that.$message.warning(res.message)
          }
        })
  },
  computed: {
    importExcelUrl: function(){
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
  methods: {
    handleClose(removedTag) {
      const tags = this.tags.filter(tag => tag !== removedTag);
      this.tags = tags;
    },
    showInput() {
      this.inputVisible = true;
      this.$nextTick(function() {
        this.$refs.input.focus();
      });
    },

    handleInputChange(e) {
      if(!testRule(e.target.value)){
        that.$message.warning("不能包含空格！");
        return
      }
      this.inputValue = e.target.value;
    },
    handleInputConfirm() {
      const inputValue = this.inputValue;
      let tags = this.tags;
      if (inputValue && tags.indexOf(inputValue) === -1) {
        tags = [...tags, inputValue];
      }
      Object.assign(this, {
        tags,
        inputVisible: false,
        inputValue: '',
      });
    },
    checkName(val){       
      var regEn = /[`~!@#$%^&*()_+<>?:"{},.\;'[\]]/im,
          regCn = /[·！#￥（——）：；“”‘、，|《。》？、【】[\]]/im;      
      if(regEn.test(val) || regCn.test(val)) {
          return false;
      }else{
        return true
      }
    },
    addHourse(record){
      this.tags=[];
      this.lineVal=0;
      this.clomnVal=0;
      this.addList = record;
      this.visibleShow = true;
    },
    handleOk(e) {
      this.confirmLoading = true;
      // if(!this.checkName(this.hourseVal)){
      //   this.$message.warning("格式错误！请输入正确格式101/102!")
      //   this.confirmLoading = false;
      //   return
      // }
      if(this.tags.length==0){
        this.$message.warning("请输入房间号！")
        return
      }
      var list={
        hotel_number:this.tags.toString(),
        line_number:this.lineVal,
        column_number:this.clomnVal,
        id:this.addList.id
      };
      getAction("/exhibition/exhibition_meeting_info/addExhibitionNumber",list)
      .then(res => {
        this.loadData();
        if (res.success) {
          this.$message.success(res.message)
        } else {
          this.$message.warning(res.message)
        }
        this.confirmLoading = false;
        this.visibleShow = false;
      })
    },
    handleCancel(e) {
      this.visibleShow = false;
    },
    closeProview(){
      this.showImg = false;
    },
    jumpProview(val){
      this.showImg = true;
      this.proviewUrl = val;
    },
    initDictConfig() {
      initDictOptions('tickets_status').then(res => {
        if (res.success) {
          this.$set(this.dictOptions, 'ticketsStatus', res.result)
        }
      })
    },
  }
}
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>